#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
	int x=0;bool f=0;char ch=getchar();
	while(ch<'0'||ch>'9')f^=(ch=='-'),ch=getchar();
	while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
int C[50][50];
inline void init(const int N=30){
	for(int i=0;i<=N;i++)C[i][0]=1;
	for(int i=1;i<=N;i++){
		for(int j=1;j<=i;j++)C[i][j]=C[i-1][j-1]+C[i-1][j];
	}
}

inline int sol(int x){
	int res=0,sum=0,ok=1;
	for(int i=29;~i;i--){
		if(x>>i&1){
			for(int j=0;j<=i;j++)res+=C[i][j]*((1ll<<(sum+j))-1);
			++sum;
		}
	}
	res+=(1ll<<sum)-1;
	return res;
}
signed main(){init();
//	freopen("comb.in","r",stdin);
//	freopen("comb.out","w",stdout);
	int S=0;
	for(int i=0;i<30;i++)S+=(1<<i);
	int q=read();
	while(q--){
		int l=read(),r=read(),res=0;
		res=sol(r)-sol(l-1);
		printf("%lld\n",res);
	}
	return 0;
}
/*
1
1 100
*/

